package com.shf.lease.web.admin.controller.apartment;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.shf.lease.entity.RoomInfo;
import com.shf.lease.enums.ReleaseStatus;
import com.shf.lease.result.Result;
import com.shf.lease.web.admin.controller.apartment.query.QueryRoomParams;
import com.shf.lease.web.admin.controller.apartment.request.RoomSubmitVo;
import com.shf.lease.web.admin.controller.apartment.response.PageListVo;
import com.shf.lease.web.admin.controller.apartment.response.RoomVo;
import com.shf.lease.web.admin.service.RoomInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author 叶枫
 * @date 2024/7/6.
 */

@Tag(name = "房间管理")
@RestController
@RequestMapping("/admin/room")
public class RoomController {

    @Resource
    private RoomInfoService roomInfoService;

    @GetMapping("/pageItem")
    public Result<PageListVo<RoomVo>> queryPageListRoom(QueryRoomParams queryParams) {
        return roomInfoService.queryPageListRoom(queryParams);
    }
    @Operation(summary = "保存或更新房间信息")
    @PostMapping("saveOrUpdate")
    public Result saveOrUpdate(@RequestBody RoomSubmitVo roomSubmitVo) {
        roomInfoService.saveOrUpdateRoom(roomSubmitVo);
        return Result.ok();
    }

    @Operation(summary = "根据id删除房间信息")
    @DeleteMapping("removeById")
    public Result removeById(@RequestParam Long id) {
        roomInfoService.removeRoomById(id);
        return Result.ok();
    }
    @Operation(summary = "根据id修改房间发布状态")
    @PostMapping("updateReleaseStatusById")
    public Result updateReleaseStatusById(Long id, ReleaseStatus status) {
        LambdaUpdateWrapper<RoomInfo> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(RoomInfo::getId, id);
        updateWrapper.set(RoomInfo::getIsRelease, status);
        roomInfoService.update(updateWrapper);
        return Result.ok();
    }
}
